package com.xiaren.util;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 * 用于测试IP通不通
 * @author xiaren
 *
 */
public class InetAddPassBtn extends JTextField{

	public InetAddPassBtn(String text) {
		super(text);
		init();
	}

	private void init(){
		this.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				String ip = InetAddPassBtn.this.getText();
				boolean flag = false;
				try {
					flag = InetAddress.getByName(ip).isReachable(2000);
				} catch (UnknownHostException ex) {
					ex.printStackTrace();
				} catch (IOException ex) {
					ex.printStackTrace();
				}
				JOptionPane.showMessageDialog(null, flag ? "通" : "不通");
			}
		});

	}



}
